﻿using UnityEngine;
using TinyWnd;

public class MainMenuWnd : Wnd
{
    GameObject goBtnRank;
    GameObject goBtnLevel;
    GameObject goBtnSkill;
    GameObject goBtnSwitch;
    UILabel lbSwitch;
    TweenPosition[] twPositions = new TweenPosition[3];
    
    bool _showBtn = true;

    protected override void OnAwake()
    {
        _wndId = WndId.mainMenu;

        var tran = transform;
        goBtnRank = Utility.FindChild(tran, "LeftBottom/01BtnRank").gameObject;
        goBtnLevel = Utility.FindChild(tran, "LeftBottom/02BtnLevel").gameObject;
        goBtnSkill = Utility.FindChild(tran, "LeftBottom/03BtnSkill").gameObject;
        goBtnSwitch = Utility.FindChild(tran, "RightBottom/BtnSwitch").gameObject;
        lbSwitch = Utility.FindChild<UILabel>(tran, "RightBottom/BtnSwitch/Label");

        twPositions[0] = goBtnRank.GetComponent<TweenPosition>();
        twPositions[1] = goBtnLevel.GetComponent<TweenPosition>();
        twPositions[2] = goBtnSkill.GetComponent<TweenPosition>();

        UIEventListener.Get(goBtnRank).onClick = delegate
        {
            var names = new string[] { "Orc Armor - Boots", "Orc Armor - Bracers", "Orc Armor - Shoulders" };
            var content = new WndRankContent();
            for (var i = 0; i < 10; i++)
            {
                var one = new RankItemData();
                one.lblName = "rank:" + (i + 1).ToString();
                one.spriteName = names[Random.Range(0, 2)];
                content.lst.Add(one);
            }
            WndMgr.inst.ShowWindow(WndId.rank, content);
        };

        UIEventListener.Get(goBtnLevel).onClick = delegate
        {
            WndMgr.inst.ShowWindow(WndId.level);
        };

        UIEventListener.Get(goBtnSkill).onClick = delegate
        {
            WndMgr.inst.ShowWindow(WndId.skill);
        };

        UIEventListener.Get(goBtnSwitch).onClick = delegate
        {
            _showBtn = !_showBtn;
            if (_showBtn)
                ShowBtns();
            else
                HideBtns();
        };
    }

    void ShowBtns()
    {
        lbSwitch.text = "On";
        for (var i = 0; i < twPositions.Length; i++)
            twPositions[i].PlayReverse();
    }

    void HideBtns()
    {
        lbSwitch.text = "Off";
        for (var i = 0; i < twPositions.Length; i++)
            twPositions[i].PlayForward();
    }
}
